package static_park

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/cars"

	"github.com/gin-gonic/gin"
)

func Entry(c *gin.Context) {

	requestDataMap := make(map[string]interface{})
	c.ShouldBindJSON(&requestDataMap)

	where, page, pageSize := controller.WhereStructure(requestDataMap)

	//查询信息
	var carsEntryStruct cars.CarsEntryStruct
	var carsEntryData []cars.CarsEntryStruct
	model.GetModelData(
		model.Db,
		carsEntryStruct.TableName(),
		&carsEntryData,
		model.QueryOptions{
			Page:       page,
			PageSize:   pageSize,
			Conditions: where,
			OrderBy:    "id desc",
		},
	)

	//数据格式化
	returnData := make([]map[string]interface{}, 0)
	for _, v := range carsEntryData {
		returnData = append(returnData, map[string]interface{}{
			"id":           v.Id,
			"park_code":    v.ParkCode,
			"park_name":    v.ParkName,
			"car_number":   v.CarNumber,
			"in_time":      v.InTime.Format("2006-01-02 15:04:05"),
			"in_photo":     v.InPhoto,
			"serial_no":    v.SerialNo,
			"region_code":  v.RegionCode,
			"region_name":  v.RegionName,
			"car_no_color": v.CarNoColor,
			"much_id":      v.MuchId,
			"order_no":     v.OrderNo,
			"order_type":   v.OrderType,
		})
	}

	//总数查询
	count, _ := model.CountModelData(
		model.Db,
		carsEntryStruct.TableName(),
		model.QueryOptions{
			Conditions: where,
		},
	)

	controller.Success(c,
		map[string]interface{}{
			"list":        returnData,
			"total":       count,
			"pageSize":    pageSize,
			"currentPage": page,
		})
}
